|
1
|
|
|
//require('env2')('.env'); // optionally store your Evironment Variables in .env |
|
2
|
|
|
|
|
3
|
|
|
const seleniumServer = require("selenium-server"); |
|
4
|
|
|
const chromedriver = require("chromedriver"); |
|
5
|
|
|
const SCREENSHOT_PATH = "./test/e2e/screenshots/"; |
|
6
|
|
|
|
|
7
|
|
|
// we use a nightwatch.conf.js file so we can include comments and helper functions |
|
8
|
|
|
module.exports = { |
|
9
|
|
|
"src_folders": [ |
|
10
|
|
|
"test/e2e/specs"// Where you are storing your Nightwatch e2e tests |
|
11
|
|
|
], |
|
12
|
|
|
"output_folder": "./test/e2e/reports", // reports (test outcome) output by nightwatch |
|
13
|
|
|
"end_session_on_fail": true, |
|
14
|
|
|
"skip_testcases_on_fail": false, |
|
15
|
|
|
"abortOnAssertionFailure": false, |
|
16
|
|
|
"selenium": { |
|
17
|
|
|
"start_process": true, // tells nightwatch to start/stop the selenium process |
|
18
|
|
|
"server_path": seleniumServer.path, |
|
19
|
|
|
"host": "127.0.0.1", |
|
20
|
|
|
"port": 4444, // standard selenium port |
|
21
|
|
|
"cli_args": { |
|
22
|
|
|
"webdriver.chrome.driver": chromedriver.path |
|
23
|
|
|
} |
|
24
|
|
|
}, |
|
25
|
|
|
"test_settings": { |
|
26
|
|
|
"default": { |
|
27
|
|
|
"screenshots": { |
|
28
|
|
|
"enabled": true, // if you want to keep screenshots |
|
29
|
|
|
"path": SCREENSHOT_PATH, // save screenshots here |
|
30
|
|
|
"on_failure" : true, |
|
31
|
|
|
"on_error" : true, |
|
32
|
|
|
}, |
|
33
|
|
|
"globals": { |
|
34
|
|
|
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait. |
|
35
|
|
|
}, |
|
36
|
|
|
"desiredCapabilities": { // use Chrome as the default browser for tests |
|
37
|
|
|
"browserName": "chrome" |
|
38
|
|
|
} |
|
39
|
|
|
}, |
|
40
|
|
|
"chrome": { |
|
41
|
|
|
"desiredCapabilities": { |
|
42
|
|
|
"browserName": "chrome", |
|
43
|
|
|
"javascriptEnabled": true // turn off to test progressive enhancement |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
}, |
|
47
|
|
|
afterEach: function (client, done) { |
|
48
|
|
|
var weHaveFailures = client.currentTest.results.errors > 0 || client.currentTest.results.failed > 0; |
|
49
|
|
|
|
|
50
|
|
|
console.log(weHaveFailures); |
|
|
|
|
|
|
51
|
|
|
if (weHaveFailures) { |
|
52
|
|
|
if (!client.sessionId) { |
|
53
|
|
|
console.log('Session already ended.'); |
|
54
|
|
|
done(); |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
var fileName = getFileName(client.currentTest.name); |
|
59
|
|
|
client.saveScreenshot(fileName, function (result) { |
|
60
|
|
|
if (!result || result.status !== 0) { |
|
61
|
|
|
console.log('Error saving screenshot...', result); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
client.end(done); |
|
64
|
|
|
}); |
|
65
|
|
|
} else { |
|
66
|
|
|
client.end(done); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function padLeft(count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/ |
|
72
|
|
|
return count < 10 ? '0' + count : count.toString(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
var FILECOUNT = 0; // "global" screenshot file count |
|
76
|
|
|
/** |
|
77
|
|
|
* The default is to save screenshots to the root of your project even though |
|
78
|
|
|
* there is a screenshots path in the config object above! ... so we need a |
|
79
|
|
|
* function that returns the correct path for storing our screenshots. |
|
80
|
|
|
* While we're at it, we are adding some meta-data to the filename, specifically |
|
81
|
|
|
* the Platform/Browser where the test was run and the test (file) name. |
|
82
|
|
|
*/ |
|
83
|
|
|
function imgpath(browser) { |
|
84
|
|
|
var a = browser.options.desiredCapabilities; |
|
85
|
|
|
var meta = [a.platform]; |
|
86
|
|
|
meta.push(a.browserName ? a.browserName : 'any'); |
|
87
|
|
|
meta.push(a.version ? a.version : 'any'); |
|
88
|
|
|
meta.push(a.name); // this is the test filename so always exists. |
|
89
|
|
|
var metadata = meta.join('~').toLowerCase().replace(/ /g, ''); |
|
90
|
|
|
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
module.exports.imgpath = imgpath; |
|
94
|
|
|
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH; |
|
95
|
|
|
|